
<%@page import="bdclass.detalle_pedido"%>
<%@page import="bdclass.pedido"%>
<%@page import="bdclass.Persona"%>
<%@page import="bdclass.clase_producto"%>
<%@page import="bdclass.Temp_Pedido"%>
<%@page import="bdclass.producto"%>
<%@page import="java.sql.ResultSet"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">
    
<%int prod;%>
<%int cantidad;%>
<%int i;%>
<head>
		<link rel="stylesheet" media="screen" type="text/css" href="css/csspop.css"/>
		<link rel="stylesheet" media="screen" type="text/css" href="css/layout.css" />
		<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
		

		<!--codigo pop up-->
		<SCRIPT LANGUAGE="JavaScript">
		<!-- Begin
			function popUp(URL) {
				day = new Date();
					id = day.getTime();
					eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=750,height=400,left = 232,top = 160');");
					}
				// End -->
		</script>
		
		<!--funcion limpiar los text-->
		<script>
 function limpia(elemento)
 {
 elemento.value = "";
 }

 function verifica(elemento)
 {
 if(elemento.value == "")
   elemento.value = "";
  }
 </script>



<!-- script insertar solo numeros-->
<script language="javascript">
function mis_datos(){
var key=window.event.keyCode;
if (key < 48 || key > 57){
window.event.keyCode=0;alert("Ingrese solo numeros");
}}
</script>
		
		
		
<style type="text/css">
#apDiv1 {
	position:absolute;
	width:374px;
	height:186px;
	z-index:1;
	left: 300px;
	top: 138px;
}
</style>
</head>
<body>
    
    <%
    try
       {
            Class.forName("org.postgresql.Driver");

            Temp_Pedido tp=new Temp_Pedido();



            if(request.getParameter("producto")!=null)
            {
                prod=Integer.parseInt(String.valueOf(request.getParameter("producto")));
                cantidad=Integer.parseInt(String.valueOf(request.getParameter("txtCantidad")));



                tp.InsertarTP(prod, cantidad);
            }
        
        

        
        
    %>
    
    
<form id="form1" method="post" action="confirmacion_pedido.jsp">
    
    <%
        ResultSet rs=tp.SelectTP();
    %>
  <table width="99%" border="0" bgcolor="#FFFFFF">
    <tr>
      <td colspan="5" align="center" style="background-color:#CCCCCC;">PEDIDO</td>
    </tr>
    <tr>
      <td colspan="2" align="center" style="background-color:#FFFFFF;">CLIENTE:</td>
      <td colspan="2" align="center">
        <select name="cbxCliente">
            <%
                    try
                    {
                        Persona per=new Persona();
                        ResultSet rsp =per.SelectPersona();
                        String nombre;

                        Class.forName("org.postgresql.Driver");

                        while(rsp.next())
                        {
                            nombre=rsp.getString("nombre")+" "+rsp.getString("apellido2")+" "+rsp.getString("apellido2");
                            
                            %>
                            <option value="<%=rsp.getInt("id_persona")%>"><%=nombre%></option>
                            <%
                        }
                           
                    }
                    catch (Exception ex) 
                    {
                        System.out.println(ex.toString());
                    }
                    
                    
                    %>

      </select></td>
      <td align="center">&nbsp;</td>
    </tr>
    <tr>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td align="center"><input type="button" name="btnAgregar" id="btnAgregar" onclick="javascript:popUp('agregar_producto.jsp')" value="AGREGAR PRODUCTO" onclick="windows.close();" /></td>
      <td align="center">&nbsp;</td>
    </tr>
    <tr>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
      <td align="center">&nbsp;</td>
    </tr>
    <tr>
      <td align="center" style="background-color:#CCCCCC;">PRODUCTO</td>
      <td align="center" style="background-color:#CCCCCC;">PRECIO</td>
      <td align="center" style="background-color:#CCCCCC;">CANTIDAD</td>
      <td align="center" style="background-color:#CCCCCC;">TOTAL</td>
      <td align="center" style="background-color:#CCCCCC;">SELECCION</td>
    </tr>
  
        <%
        i=0;
        clase_producto cp=new clase_producto();
        producto p=new producto();
            while(rs.next())
            {
                i++;
                
                prod=rs.getInt("id_producto");
                cantidad=rs.getInt("cantidad");
                cp=p.SelectProdPorId(prod);
                
                %>  <tr>
                        <td>
                            <input name=<%="txtProd"+i%> type="text" readonly="readonly" value="<%=cp.getNombre()%>"/>
                        </td>
                        <td>
                            <input name=<%="txtPrecio"+i%> type="text" readonly="readonly" value="<%="$ "+cp.getPrecio()%>"/>
                        </td>
                        <td>
                            <input name=<%="txtCantidad"+i%> type="text" readonly="readonly" value="<%=cantidad%>"/>

                        </td>
                        <td>
                            <input name=<%="txtTota"+i%> type="text" readonly="readonly" value="<%=cantidad*cp.getPrecio()%>"/>
                            <input type="hidden" name=<%="txtIdP"+i%> value="<%=prod%>"/></td>
                        <td align="center"><input name=<%="confirmIdProd"+i%> type="checkbox" value="1" checked="checked" /></td>
                </tr> 
                 <%
            }
        %>
            
      
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td align="center">&nbsp;</td>
    </tr>
    <tr>
        <input type="hidden" name=<%="txtCantidad"%> value="<%=i%>"/>
      <td colspan="2" align="center"><input type="submit" name="btnOk" id="btnOk" value="REALIZAR PEDIDO" /></td>
      <td>&nbsp;</td>
      <td colspan="2" align="center">&nbsp;</td>
    </tr>
  </table>
</form>
       
        <%
        }catch(Exception e)
        {
            System.err.println(e.toString());
        }
%>               
        
</body>
</html>